﻿using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;

namespace MS.InformationManagement.Records.ObjectDef.Receivers.SectionEventReceiver
{
    /// <summary>
    /// List Item Events
    /// </summary>
    public class SectionEventReceiver : SPItemEventReceiver
    {
       /// <summary>
       /// An item is being deleted.
       /// </summary>
       public override void ItemDeleting(SPItemEventProperties properties)
       {
           base.ItemDeleting(properties);
           if (properties.List.Title.Equals("Secciones"))
           {
               try
               {
                   this.EventFiringEnabled = false;
                   //if (!properties.Web.CurrentUser.IsSiteAdmin)
                   //{
                       properties.Cancel = true;
                       properties.ErrorMessage = string.Format("No es posible eliminar items de esta lista."
                           , properties.Web.CurrentUser.LoginName);
                   //}
               }
               catch (Exception ex)
               {
                   Logger.LogException(ex, Microsoft.SharePoint.Administration.EventSeverity.Error,
                        SPDiagnosticsAreas.SHAREPOINTFOUNDATION, SPDiagnosticsAreas.SharepointFoundationDiagnosticsCategories.WEBPARTS);
                   throw;
               }
               finally { this.EventFiringEnabled = true; }
           }
       }


    }
}
